package com.houtai.servicebase.exceptionhandler;
import com.houtai.commonutils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
@Slf4j
public class GExceptionHandler {
    @ExceptionHandler(Exception.class)
    @ResponseBody//返回数据
    public Result error(Exception e){
        e.printStackTrace();
        return Result.error().message("执行了全局异常处理");

    }
    //特定异常
    @ExceptionHandler(ArithmeticException.class)
    @ResponseBody//返回数据
    public Result error(ArithmeticException e){
        e.printStackTrace();
        return Result.error().message("执行了Arithmetic异常处理");

    }
    //自定义异常
    @ExceptionHandler(DException.class)
    @ResponseBody//返回数据
    public Result error(DException e){
        e.printStackTrace();
        log.error(e.getMessage());
        return Result.error().code(e.getCode()).message(e.getMsg());

    }
}
